package org.finesys.boot.config;

import org.springdoc.core.AbstractSwaggerUiConfigProperties;
import org.springdoc.core.SwaggerUiConfigProperties;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "springdoc.api-docs.enabled", matchIfMissing = true)
public class SpringDocConfiguration implements InitializingBean {

    private final SwaggerUiConfigProperties swaggerUiConfigProperties;
    @Value("${spring.application.name}")
    private String applicationName;
    public static final String API_URI = "/%s/v3/api-docs";
    @Override
    public void afterPropertiesSet() throws Exception {

     AbstractSwaggerUiConfigProperties.SwaggerUrl swaggerUrl = new AbstractSwaggerUiConfigProperties.SwaggerUrl();
        swaggerUrl.setName(applicationName);
        swaggerUrl.setUrl(String.format(SpringDocConfiguration.API_URI, applicationName));
        swaggerUiConfigProperties.setUrl(API_URI);
    }
}
